const tool = require('../tool');

const fs = require('fs');

const handleInitAddPage = require('../module/add_page/add_page'); 

//添加/编辑 页面
module.exports = async function addPageGenerate(module_config, add_page) {
  var module_config = module_config;

    //是否初次生成的字段
    var isGenerate = add_page.isGenerate;
    if(isGenerate == 'false') {
      return;
    }

    

  var addPageObj = handleInitAddPage(module_config, add_page);

  var {
    totalTplCode,     //模板
    inputDataContent, //输入data
    methodsCodeFirst,
    methodsCodeSecond,    //方法
    mountedCode
  } = addPageObj;


  //引入去除未使用的插值字符串
  const finalHandle = require('../module/final_handle'); //最后处理未使用的数据

  var add_page_name = 'add_page';
  if (add_page.add_page_name) {
    add_page_name = add_page.add_page_name;
  }

  //生成文件
  tool.generateFunc({
    tipsText: add_page.tipsText,
    filePath: `./template/add_page_tpl.vue`,
    outputPath: `../src/pages/${module_config.module_name}/${add_page_name}.vue`,
    templateCode: totalTplCode,  //1
    mountedCode: mountedCode,
    methodsCodeFirst: methodsCodeFirst,  //2
    methodsCodeSecond: methodsCodeSecond,
    dataCode: inputDataContent,  //3
    // styleCode: '',
  }, finalHandle);
}



